package com.aas.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.sql.Time;

/**
 * 状态约束校验器
 * 2022.10.31
 *
 * @author yuluxingchen
 * @version 1.0.0
 */

public class FlagValidatorClass implements ConstraintValidator<FlagValidator, Integer> {
    private String[] values = {"1", "2", "3", "4"};

    @Override
    public void initialize(FlagValidator flagValidator) {
        this.values = flagValidator.value();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (value == null) {
            return true;
        }

        for (String v : values) {
            if (v.equals(String.valueOf(value))) {
                return true;
            }
        }
        return false;
    }
}
